#!/usr/bin/perl -w
use strict;
use warnings;
use Carp;
use File::Basename;
#print basename($0)."\n";
if (@ARGV!=2) {
        die "Usage:splitfasta.pl inputfile fastaseqnumber\n";
}
open(SEQ,"< $ARGV[0]")||die "Can't open $ARGV[0]\n" ;
my $a=0;
my $i=1;
my $file=basename($ARGV[0]);
open(WF,"> $file\_1")||die"Can't write to $file\_1:$!\n";
while (<SEQ>) {
  chomp;
  if(/>/){  	
  	 if($a>=$ARGV[1]){
  	   close WF;
  	   $a=0;
  	   $i++;
  	   open(WF,"> $file\_$i")||die"Can't write to $file\_$i:$!\n";
     }
     $a++;
  	#print "$a\n";
  	print WF "$_\n";
  }else{
  	print WF "$_\n";
  }
}
close WF;
close SEQ;